//
//  SMHDataSalesInfoView.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/6/2.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit

class SMHDataSalesInfoView: LZBaseView {
    var viewModel = SMHDataViewModel()
    override init(viewModel: LZBaseViewModel) {
        super.init(viewModel: viewModel)
        self.viewModel = viewModel as! SMHDataViewModel
        self.backgroundColor = UIColor.white
        self.setupUI()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


    //MARK:_setupUI
    func setupUI()  {

    //MARK:我的销售额
        let salesLab = UILabel()
        salesLab.text = "我的销售额"
        salesLab.textColor = UIColorFromHex(rgbValue: 0x363636)
        salesLab.font = ktextBoldFont(size: 15)
        self.addSubview(salesLab)
        salesLab.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.height.equalTo(50)
            make.width.equalTo(120)
            make.top.equalTo(0)
        }

        
        let salesLineView = UIView()
        salesLineView.backgroundColor = UIColorFromHex(rgbValue: 0xE5E5E5)
        self.addSubview(salesLineView)
        salesLineView.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.height.equalTo(0.8)
            make.width.equalTo(kScreenWidth-30)
            make.top.equalTo(49)
        }
        
        //零售营业额
        let retailLab = UILabel()
        retailLab.text = "零售营业额(元)"
        retailLab.textColor = UIColorFromHex(rgbValue: 0xA8A8A8)
        retailLab.font = ktextFont(size: 14)
        self.addSubview(retailLab)
        retailLab.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.height.equalTo(14)
            make.width.equalTo((kScreenWidth-40)/2.0)
            make.top.equalTo(salesLineView.snp.bottom).offset(20)
        }

        ///营业额
        let retailNumLab = UILabel()
        retailNumLab.text = "0.00"
        retailNumLab.textColor = UIColorFromHex(rgbValue: 0x363636)
        retailNumLab.font = ktextBoldFont(size: 18)
        self.addSubview(retailNumLab)
        retailNumLab.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.height.equalTo(17)
            make.width.equalTo(retailLab)
            make.top.equalTo(retailLab.snp.bottom).offset(10)
        }

        
        
        //零售营业额
        let wholesaleLab = UILabel()
        wholesaleLab.text = "批发营业额(元)"
        wholesaleLab.textColor = UIColorFromHex(rgbValue: 0xA8A8A8)
        wholesaleLab.font = ktextFont(size: 14)
        self.addSubview(wholesaleLab)
        wholesaleLab.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.height.equalTo(14)
            make.width.equalTo(retailLab)
            make.top.equalTo(retailLab)
        }

        ///营业额
        let wholesaleNumLab = UILabel()
        wholesaleNumLab.text = "0.00"
        wholesaleNumLab.textColor = UIColorFromHex(rgbValue: 0x363636)
        wholesaleNumLab.font = ktextBoldFont(size: 18)
        self.addSubview(wholesaleNumLab)
        wholesaleNumLab.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.height.equalTo(17)
            make.width.equalTo(wholesaleLab)
            make.top.equalTo(retailNumLab)
        }


        
        ///详情
        let detailView = UIView()
        detailView.backgroundColor = UIColorFromHex(rgbValue: 0xF2F2F2)
        self.addSubview(detailView)
        detailView.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.height.equalTo(28)
            make.width.equalTo(kScreenWidth-30)
            make.top.equalTo(wholesaleNumLab.snp.bottom).offset(12)
        }
        detailView.clipRectCorner(direction: .allCorners, cornerRadius: 1)

        
        let details :[String] = ["顾客数 0","预售订单 0","批发订单 0"]
        
        for (index,item) in details.enumerated() {
            let detailLab = UILabel()
            detailLab.text = item
            detailLab.textColor = UIColorFromHex(rgbValue: 0x363636)
            detailLab.font = ktextFont(size: 12)
            detailLab.adjustsFontSizeToFitWidth = true
            detailView.addSubview(detailLab)
            detailLab.snp.makeConstraints { (make) in
                make.left.equalTo(index * (Int((kScreenWidth-30))/details.count) + 15)
                make.height.equalTo(28)
                make.width.equalTo(Int((kScreenWidth-60))/details.count)
                make.top.equalTo(0)
            }
        }
        
        
             
                


        //零售订单
        let stagingOrderLabel = UILabel()
        stagingOrderLabel.text = "零售订单"
        stagingOrderLabel.textColor = UIColorFromHex(rgbValue: 0x363636)
        stagingOrderLabel.font = ktextFont(size: 15)
        self.addSubview(stagingOrderLabel)
        stagingOrderLabel.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.height.equalTo(50)
            make.width.equalTo(120)
            make.top.equalTo(detailView.snp.bottom).offset(20)
        }

        let statusName :[String] = ["全部","待付款","待发货","已发货","已完成"];
        let statusImageName :[String] = ["icon_order_all","icon_order_payment","icon_order_shipped_not","icon_order_shipped","icon_order_complete"]


        let witdth :Int = Int(kScreenWidth)/statusName.count
        var badgeLabs = Array<UILabel>()
        for (index,item) in statusName.enumerated(){

            let statusBtn = UIButton()
            statusBtn.setTitle(item, for: .normal)
            statusBtn.setTitleColor(UIColorFromHex(rgbValue: 0x868686), for: .normal)
            statusBtn.titleLabel?.font = ktextFont(size: 12)
            statusBtn.setImage(UIImage.init(named: statusImageName[index]), for: .normal)
            statusBtn.tag = 100 + index
            self.addSubview(statusBtn)
            statusBtn.snp.makeConstraints { (make) in
                make.left.equalTo(index * witdth)
                make.top.equalTo(stagingOrderLabel.snp.bottom)
                make.width.equalTo(witdth)
                make.height.equalTo(45)
            }
            statusBtn.layoutButtonEdgeInsets(style: .ButtonEdgeInsetsStyleTop, space: 6)

            let badgeLab = UILabel()
            badgeLab.backgroundColor = UIColorFromHex(rgbValue: 0xFF661B)
            self.addSubview(badgeLab)
            badgeLab.snp.makeConstraints { (make) in
                make.left.equalTo(statusBtn.snp.centerX).offset(8)
                make.top.equalTo(statusBtn.snp.top).offset(-5)
                make.height.equalTo(10);
                make.width.equalTo(10);
            }
            badgeLab.clipRectCorner(direction: .allCorners, cornerRadius: 5)
            badgeLabs.append(badgeLab)
        }
    }
}
